<?php

class Core_Controller_Admincp_Theme_Default extends Nuo_Controller_Admincp
{
	function execute($request)
	{
		$id = $request -> getParam('theme_id');

		$table = Nuo::getTable('core/theme');

		$item = NULL;

		if ($id)
		{
			$item = $table -> find($id) -> current();
		}

		$table -> update(array('is_default' => 0));

		Nuo::getApi('core/config') -> write('core', array('default_theme' => $item -> theme_id));

		$item -> is_default = 1;

		$item -> save();

		// add messenger
		Nuo_Messenger::instance() -> add(Intl::__('Changed default theme!'));

		// remove old cache key!
		Nuo_Cache::instance() -> remove($key = 'ape/config');

		Nuo::getHook() -> trigger('themeChanged', $item);

		$uri = Nuo::getUrl('admincp/core/theme');

		Nuo::redirect($uri);
	}

}
